package org.one.stone.soup.grfxML.plugin;

import org.one.stone.soup.grfxML.DataPlugin;
import org.one.stone.soup.grfxML.GrfxMLEngine;
import org.one.stone.soup.grfxML.NameHelper;
import org.one.stone.soup.grfxML.TagModifier;
import org.one.stone.soup.mjdb.data.field.DataLinker;
import org.one.stone.soup.mjdb.data.field.Field;
import org.one.stone.soup.mjdb.data.field.LockException;

public abstract class SimplePlugin extends DataPlugin {

/**
 * GeneratorPlugin constructor comment.
 */
public SimplePlugin(GrfxMLEngine engine) {
	super(engine);
}
/**
 * compare method comment.
 */
public int compare(org.one.stone.soup.mjdb.data.field.Field target) throws org.one.stone.soup.mjdb.data.field.CompareException {
	return 0;
}
public Field getArg(Field target,int index,DataLinker store)
{
	if(getData().size()>index && getData().get(index).getClass() == target.getClass())
	{
		try{
			store.add((Field)getData().get(index),this);
		}
		catch(LockException le){}//dummy catch

		return (Field)getData().get(index);
	}
	else
		return target;
}
/**
 * getClone method comment.
 */
public org.one.stone.soup.grfxML.DataPlugin getClone() {
	return null;
}
/**
 * getClone method comment.
 */
public org.one.stone.soup.grfxML.DataPlugin getClone(String path) {
	return null;
}
/**
 * getValue method comment.
 */
public String getValue(String name) {
	return null;
}
public void registerField(Field field, DataLinker store)
{
	java.lang.reflect.Field[] fields = this.getClass().getDeclaredFields();

	String name=null;

	for(int loop=0;loop<fields.length;loop++)
	{
		try{
			if(fields[loop].get(this) == field)
			{
				name = fields[loop].getName();
				break;
			}
		}catch(IllegalAccessException ie){}//dummy catch
	}

	try{
		String path = getPath();
		if(path!=null && path!="" && !NameHelper.isSystemName(path))
			name = path+name;

		field.setId(name,(Field)this);

		store.add(field,this);
	}
	catch(LockException le){}//dummy catch
}
public void registerFieldAs(Field field, String name, DataLinker store)
{

	try{
		String path = getPath();
		if(path!=null && path!="" && !NameHelper.isSystemName(path))
			name = path+name;

		field.setId(name,(Field)this);

		store.add(field,this);
	}
	catch(LockException le){}//dummy catch
}
public void registerPart(Object target,String subPath,Field field, DataLinker store)
{
	java.lang.reflect.Field[] fields = target.getClass().getDeclaredFields();

	String name=null;

	for(int loop=0;loop<fields.length;loop++)
	{
		try{
			if(fields[loop].get(target) == field)
			{
				name = fields[loop].getName();
				break;
			}
		}catch(IllegalAccessException ie){}//dummy catch
	}

	try{
		if(subPath!=null && subPath!="" && !NameHelper.isSystemName(subPath))
			name = subPath+name;

		field.setId(name,(Field)this);

		store.add(field,this);
	}
	catch(LockException le){}//dummy catch
}
public void replace(Field oldObj, Field newObj,boolean recursive)
{
	replace(oldObj,newObj);
}
public String togrfxML(String name,TagModifier modifier) {
	return togrfxML(name);
}
}
